import request from '../../request';
import { AxiosResponse } from 'axios';
import { ResponseData } from '@/types/api/public';
import { TableList, EditData, DataSourceTableInput } from '@/types/api/datasources/datasource';

type ConfigType<T = ResponseData> = Promise<AxiosResponse<T>>

/**
 * 获取数据
 * @param params 参数
 * @returns 分页数据
 */
export const getData = (params: any): ConfigType<TableList> => {
  params.PageIndex = params.current;
  params.PageSize = params.pageSize;

  return request({
    url: '/api/v1/Online/GetPageList',
    method: 'get',
    params,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const getDataSourceTables = (): ConfigType<TableList> => {
  return request({
    url: '/api/v1/DataSource/GetAllDataSourceTables',
    method: 'get',
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const saveOrUpdateDataSource = (data: any): ConfigType<TableList> => {
  return request({
    url: '/api/v1/Online/SetOnlineInfo',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const getOnlineFieldsByOnlineInfoId = (params: any): ConfigType<TableList> => {
  return request({
    url: '/api/v1/Online/GetOnlineFieldsByOnlineInfoId',
    method: 'get',
    params,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const getTableColumnData = (params: any): ConfigType<TableList> => {
  return request({
    url: '/api/v1/DataSource/QueryDataSourceColumnsByTableId',
    method: 'get',
    params,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const getOnlineInfoByFormCode = (params: any): ConfigType<TableList> => {
  return request({
    url: '/api/v1/Online/GetOnlineInfoByFormCode',
    method: 'get',
    params,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}